package com.XSQS.util;

import java.util.LinkedList;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class Utility {

	static {
		PropertyConfigurator.configure("config/log.properties");
	}

	
	/**
	 * Get the logger for the specified Class.
	 * @param clazz
	 * @return the logger for the specified Class.
	 */
	public static Logger getLogger(Class<?> clazz){
		return Logger.getLogger(clazz);
	}

	/**
	 * Get the intersection of the A and B.
	 * 
	 * @param <T>
	 * @param A
	 * @param B
	 * @return return the array which is the intersection of the A and B.
	 */
	@SuppressWarnings("unchecked")
	public static <T> T[] getIntersection(T[] A, T[] B) {
		if (A == null || B == null)
			return null;
		List<T> list = new LinkedList<T>();
		for (T a : A) {
			for (T b : B) {
				if (a.equals(b)) {
					list.add(a);
				}
			}
		}
		T[] C = (T[]) java.lang.reflect.Array.newInstance(A.getClass()
				.getComponentType(), list.size());
		return list.toArray(C);
	}
}
